package com.tbit.uqbike.webmanager.controller;

import com.tbit.uqbike.object.pojo.dto.RideCardUsedDownloadDTO;
import com.tbit.uqbike.object.pojo.vo.CardUseLogVO;
import com.tbit.common.entity.view.PageResult;
import com.tbit.common.entity.view.Result;
import com.tbit.uqbike.service.business.CardUseLogService;
import com.tbit.uqbike.webmanager.util.csv.annotations.AsyncDownload;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotNull;
import java.util.Date;

/**
 * 卡券使用记录
 *
 * @Author:BUGTian
 * @DATE: 2023/1/6
 */
@RestController
@RequestMapping("/cardUseLog")
public class CardUseLogController {

    @Autowired
    private CardUseLogService cardUseLogService;


    /**
     * 分页查询卡券使用记录
     *
     * @param page          当前页码
     * @param size          每页显示的行
     * @param brandId       品牌id
     * @param buyAccountIds 购买区域id
     * @param useAccountIds 使用区域id
     * @param cardType      卡券类型 2:骑行卡
     * @param startTime     开始时间
     * @param endTime       结束时间
     * @return
     */
    @GetMapping("/queryPage")
    public Result<PageResult<CardUseLogVO>> queryPage(@NotNull Integer page, @NotNull Integer size, @NotNull Integer brandId, String buyAccountIds, String useAccountIds, Integer cardType, Date startTime, Date endTime) {
        PageResult<CardUseLogVO> pageResult = cardUseLogService.queryPage(page, size, brandId, buyAccountIds, useAccountIds, cardType, startTime, endTime);
        return Result.success(pageResult);
    }

    /**
     * 导出卡券使用记录
     *
     * @param downloadDTO .
     * @return .
     */
    @AsyncDownload(defaultFileName = "卡券使用记录")
    @GetMapping("/export")
    public Result<String> export(@Validated RideCardUsedDownloadDTO downloadDTO) {
        String url = cardUseLogService.export(downloadDTO.getBrandId(), downloadDTO.getBuyAccountIds(), downloadDTO.getUseAccountIds(),
                downloadDTO.getCardType(), downloadDTO.getStartTime(), downloadDTO.getEndTime());
        return Result.success(url);
    }

}
